home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
bor_ti.exe
/
TI1160.ASC
< prev
next >
Wrap
Text File
|
1992-12-03
|
21KB
|
793 lines
PRODUCT : Borland C++ NUMBER : 1160
VERSION : 3.1
OS : DOS
DATE : December 3, 1992 PAGE : 1/12
TITLE : Dynamically modifying Turbo Vision menus.
This document provides source code to an example which
dynamically modifies menus using Turbo Vision for C++.
/***********************************************************************
* *
* MMENU.CPP *
* This module contains the code to support the TMultiMenu class. *
* *
***********************************************************************/
#define Uses_TEvent
#define Uses_TMenu
#define Uses_TSubMenu
#define Uses_TMenuItem
#define Uses_TMenuBar
#include <tv.h>
#if !defined( __MMENU_H )
#include "mmenu.h"
#endif
/***********************************************************************
* global operator +
*
* Since the objects will always be in a linked list, and the operator+
* is processd left-to-right, we will define the function as appending
* menuItem2 to menuItem1, and then return menuItem1.
***********************************************************************/
TMenuItem& operator +( TMenuItem& menuItem1, TMenuItem& menuItem2 )
{
TMenuItem *p = &menuItem1;
while( p->next != NULL )
p = p->next;
p->next = &menuItem2;
return menuItem1;
}
/***********************************************************************
* *
PRODUCT : Borland C++ NUMBER : 1160
VERSION : 3.1
OS : DOS
DATE : December 3, 1992 PAGE : 2/12
TITLE : Dynamically modifying Turbo Vision menus.
* class TTestList *
* *
***********************************************************************
* TMultiMenu::TMultiMenu
* Constructor for a TMultiMenu object. This version takes an array
* of TMenu pointers.
***********************************************************************/
TMultiMenu::TMultiMenu( const TRect& bounds, TMenu *aMenu[],
int nMenus ) : TMenuBar( bounds, aMenu[0] ),
mList( new TMenu *[nMenus] )
{
if( nMenus == 0)
for( nMenus = 0; aMenu[nMenus] != NULL; nMenus++ )
;
numMenus = nMenus;
for( int i = 0; i < nMenus; i++ )
mList[i] = aMenu[i];
}
/***********************************************************************
* TMultiMenu::TMultiMenu
* Constructor for a TMultiMenu object. This version takes an array
* of TSubMenu objects.
***********************************************************************/
TMultiMenu::TMultiMenu( const TRect& bounds, TSubMenu aMenu[],
int nMenus ) :
TMenuBar( bounds, aMenu[0] ),
numMenus( nMenus ),
mList( new TMenu *[nMenus] )
{
mList[0] = menu; // First menu is already allocated.
for( int i = 1; i < nMenus; i++ )
mList[i] = new TMenu( aMenu[i] );
}
/***********************************************************************
* TMultiMenu::~TMultiMenu
* Destructor for a TMultiMenu object. Destroys any stored menus
PRODUCT : Borland C++ NUMBER : 1160
VERSION : 3.1
OS : DOS
DATE : December 3, 1992 PAGE : 3/12
TITLE : Dynamically modifying Turbo Vision menus.
* except for the current one (which will be destroyed by ~TMenuBar)
* and frees the space where the list was stored.
***********************************************************************/
TMultiMenu::~TMultiMenu()
{
for( int i = 0; i < numMenus; i++ )
if( mList[i] != menu ) // Delete all but current menu.
delete mList[i];
delete [] mList;
}
/***********************************************************************
* TMultiMenu::handleEvent
* Code to respond to the cmMMChangeMenu broadcast message. The
* data the arrives with this message specifies which menu to switch
* to, passed via the infoInt data member of TEvent.
***********************************************************************/
void TMultiMenu::handleEvent( TEvent& event )
{
if( event.what == evBroadcast &&
event.message.command == cmMMChangeMenu )
{
if( event.message.infoInt >= 0 &&
event.message.infoInt < numMenus )
{
if( menu != mList[ event.message.infoInt ] )
{
menu = mList[ event.message.infoInt ];
drawView();
}
}
clearEvent( event );
}
else
TMenuBar::handleEvent( event );
}
PRODUCT : Borland C++ NUMBER : 1160
VERSION : 3.1
OS : DOS
DATE : December 3, 1992 PAGE : 4/12
TITLE : Dynamically modifying Turbo Vision menus.
/***********************************************************************
* *
* TEST.CPP *
* This module contains the Turbo Vision application code to run *
* this example. It sets up the necessary menus to bring up the *
* test module represented by this demo. *
* *
* TEST MODULE for Multiple Menu Bar Demo. *
* *
***********************************************************************
* *
* This code was written by Borland Technical Support. *
* It is provided as is with no warranties expressed or implied. *
* *
***********************************************************************/
#define Uses_TRect
#define Uses_TKeys
#define Uses_TEvent
#define Uses_TDialog
#define Uses_TMenu
#define Uses_TMenuItem
#define Uses_TMenuBar
#define Uses_TDeskTop
#define Uses_TProgram
#define Uses_TApplication
#include <tv.h>
#pragma hdrstop
#if !defined( __CMDS_H )
#include "cmds.h"
#endif
#if !defined( __MMENU_H )
#include "mmenu.h"
#endif
/***********************************************************************
*
* Application object for demo.
*
PRODUCT : Borland C++ NUMBER : 1160
VERSION : 3.1
OS : DOS
DATE : December 3, 1992 PAGE : 5/12
TITLE : Dynamically modifying Turbo Vision menus.
***********************************************************************/
class TTestApp : public TApplication
{
public:
TTestApp();
static TMenuBar *initMenuBar( TRect r );
virtual void handleEvent( TEvent& event );
protected:
int curMenu;
};
/***********************************************************************
*
* TTestApp::TTestApp()
*
* Application object contructor.
*
***********************************************************************/
TTestApp::TTestApp() :